#include <signal.h>
#include <iostream>
#include <sstream>
#include <boost/algorithm/string.hpp>
#include "WatchDog.h"
#include "../smtp/core/Receiver.h"

namespace kc_sf
{
	void setLocaleToUtf8()
	{
		std::locale utf8_pl("pl_PL.utf8");
		std::locale::global(utf8_pl);
		std::ios::sync_with_stdio(false);
		std::cout.imbue(utf8_pl);
		std::wcout.imbue(utf8_pl);
	}

	void sigint_handler( int sig ) // obsluga Ctrl+C
	{
		if( sig == SIGINT )
		{
			std::cout << "Wciśnięto Ctrl-C. System kończy działanie ..." << std::endl;
			SERV_END = true;

			exit( 1 );
		}
	}
}

using namespace kc_sf;

int main( int argc, char *argv[] )
{
	setLocaleToUtf8();

	bool config_from_xml = false;
	if( argc > 1 )
	{
		std::string xml_option = argv[ 1 ];
		if( !boost::iequals( xml_option, "-xmlconfig" ) )
		{
			std::cerr << "Błąd. Nie rozpoznano polecenia!" << std::endl
				<< "Składnia to:" << std::endl
				<< "kc_smtp_filter [-xmlconfig]" << std::endl;

			return -1;
		}
	}

    // utworzenie watch-doga
    WatchDog::getInstance( config_from_xml );

    return 0;
}
